package com.shuai.frame.factory;

import com.shuai.frame.constant.SerializerConstant;
import com.shuai.frame.serializer.*;
import com.shuai.frame.spi.XSRpcSPILoader;

import java.util.concurrent.ConcurrentHashMap;

public class SerializerFactory {

    static {
        XSRpcSPILoader.loadSPIImpl();
    }

    /**
     * 获取指定的序列化器
     *
     * @param serializerKey SPI-【Serializer】实现中的序列化器key值
     * @return Serializer
     */
    public static Serializer getSerializer(String serializerKey) {
        try {
            return XSRpcSPILoader.getInstance(Serializer.class, serializerKey);
        } catch (InstantiationException | IllegalAccessException e) {
            throw new RuntimeException(e);
        }
    }
}
